package com.iotimc.attendancesystem.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.iotimc.attendancesystem.entity.BasicSettingEntity.ButtonType;
import com.iotimc.attendancesystem.entity.BasicSettingEntity.ButtonTypeConverter;
import com.iotimc.attendancesystem.entity.BasicSettingEntity.DeviceType;
import com.iotimc.attendancesystem.entity.BasicSettingEntity.DeviceTypeConverter;

import com.iotimc.attendancesystem.entity.BasicSettingEntity;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "BASIC_SETTING_ENTITY".
*/
public class BasicSettingEntityDao extends AbstractDao<BasicSettingEntity, Long> {

    public static final String TABLENAME = "BASIC_SETTING_ENTITY";

    /**
     * Properties of entity BasicSettingEntity.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_id");
        public final static Property ButtonType = new Property(1, Integer.class, "buttonType", false, "BUTTON_TYPE");
        public final static Property DeviceType = new Property(2, Integer.class, "deviceType", false, "DEVICE_TYPE");
        public final static Property CompanyName = new Property(3, String.class, "companyName", false, "COMPANY_NAME");
        public final static Property Time = new Property(4, int.class, "time", false, "TIME");
        public final static Property DoorIp = new Property(5, String.class, "doorIp", false, "DOOR_IP");
        public final static Property SimilarityScore = new Property(6, int.class, "similarityScore", false, "SIMILARITY_SCORE");
        public final static Property DelayDoorSecond = new Property(7, int.class, "delayDoorSecond", false, "DELAY_DOOR_SECOND");
        public final static Property Password = new Property(8, String.class, "password", false, "PASSWORD");
    }

    private final ButtonTypeConverter buttonTypeConverter = new ButtonTypeConverter();
    private final DeviceTypeConverter deviceTypeConverter = new DeviceTypeConverter();

    public BasicSettingEntityDao(DaoConfig config) {
        super(config);
    }
    
    public BasicSettingEntityDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"BASIC_SETTING_ENTITY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
                "\"BUTTON_TYPE\" INTEGER," + // 1: buttonType
                "\"DEVICE_TYPE\" INTEGER," + // 2: deviceType
                "\"COMPANY_NAME\" TEXT," + // 3: companyName
                "\"TIME\" INTEGER NOT NULL ," + // 4: time
                "\"DOOR_IP\" TEXT," + // 5: doorIp
                "\"SIMILARITY_SCORE\" INTEGER NOT NULL ," + // 6: similarityScore
                "\"DELAY_DOOR_SECOND\" INTEGER NOT NULL ," + // 7: delayDoorSecond
                "\"PASSWORD\" TEXT);"); // 8: password
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BASIC_SETTING_ENTITY\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, BasicSettingEntity entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
 
        ButtonType buttonType = entity.getButtonType();
        if (buttonType != null) {
            stmt.bindLong(2, buttonTypeConverter.convertToDatabaseValue(buttonType));
        }
 
        DeviceType deviceType = entity.getDeviceType();
        if (deviceType != null) {
            stmt.bindLong(3, deviceTypeConverter.convertToDatabaseValue(deviceType));
        }
 
        String companyName = entity.getCompanyName();
        if (companyName != null) {
            stmt.bindString(4, companyName);
        }
        stmt.bindLong(5, entity.getTime());
 
        String doorIp = entity.getDoorIp();
        if (doorIp != null) {
            stmt.bindString(6, doorIp);
        }
        stmt.bindLong(7, entity.getSimilarityScore());
        stmt.bindLong(8, entity.getDelayDoorSecond());
 
        String password = entity.getPassword();
        if (password != null) {
            stmt.bindString(9, password);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, BasicSettingEntity entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
 
        ButtonType buttonType = entity.getButtonType();
        if (buttonType != null) {
            stmt.bindLong(2, buttonTypeConverter.convertToDatabaseValue(buttonType));
        }
 
        DeviceType deviceType = entity.getDeviceType();
        if (deviceType != null) {
            stmt.bindLong(3, deviceTypeConverter.convertToDatabaseValue(deviceType));
        }
 
        String companyName = entity.getCompanyName();
        if (companyName != null) {
            stmt.bindString(4, companyName);
        }
        stmt.bindLong(5, entity.getTime());
 
        String doorIp = entity.getDoorIp();
        if (doorIp != null) {
            stmt.bindString(6, doorIp);
        }
        stmt.bindLong(7, entity.getSimilarityScore());
        stmt.bindLong(8, entity.getDelayDoorSecond());
 
        String password = entity.getPassword();
        if (password != null) {
            stmt.bindString(9, password);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    @Override
    public BasicSettingEntity readEntity(Cursor cursor, int offset) {
        BasicSettingEntity entity = new BasicSettingEntity( //
            cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : buttonTypeConverter.convertToEntityProperty(cursor.getInt(offset + 1)), // buttonType
            cursor.isNull(offset + 2) ? null : deviceTypeConverter.convertToEntityProperty(cursor.getInt(offset + 2)), // deviceType
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // companyName
            cursor.getInt(offset + 4), // time
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // doorIp
            cursor.getInt(offset + 6), // similarityScore
            cursor.getInt(offset + 7), // delayDoorSecond
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // password
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, BasicSettingEntity entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setButtonType(cursor.isNull(offset + 1) ? null : buttonTypeConverter.convertToEntityProperty(cursor.getInt(offset + 1)));
        entity.setDeviceType(cursor.isNull(offset + 2) ? null : deviceTypeConverter.convertToEntityProperty(cursor.getInt(offset + 2)));
        entity.setCompanyName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setTime(cursor.getInt(offset + 4));
        entity.setDoorIp(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setSimilarityScore(cursor.getInt(offset + 6));
        entity.setDelayDoorSecond(cursor.getInt(offset + 7));
        entity.setPassword(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(BasicSettingEntity entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(BasicSettingEntity entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(BasicSettingEntity entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
